import java.util.Scanner;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 22652
 * Date: 2024-04-29
 * Time: 18:11
 */
public class demo_1 {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int num = in.nextInt();
        while (num > 0) {
            // 打了几场比赛和连胜星数
            int thing = in.nextInt();
            int xingshu = in.nextInt();
            //战绩
            String zhanji = in.next();
            char[] chars = zhanji.toCharArray();
            //记录连胜是大于3
            int flag = 0;
            //星数差
            int ret = 0;
            for (int i = 0; i < thing; i++) {
                if (chars[i] == 'W') {
                    flag++;
                    if (flag >= 3) {
                        ret += xingshu;
                    } else {
                        ret++;
                    }
                } else {
                    ret--;
                    flag = 0;
                }
            }
            System.out.println(ret);
            num--;
        }
    }
}
